//
//  XBookkeepingEditViewController.m
//  iAccountBook
//
//  Created by 侯伟 on 2021/9/21.
//

#import "XBookkeepingEditViewController.h"
#import "XInComeViewController.h"
#import "XExpendViewController.h"


@interface XBookkeepingEditViewController (){
    NSArray* _pageInfos;
}

@end

@implementation XBookkeepingEditViewController

- (instancetype)init{
    if(self = [super init]){
        
        [self initPageInfo];
        
        self.titleColorSelected = COLOR_WHITE;
        self.titleColorNormal = COLOR_WHITE;
        self.titleFontSelected = FONTBOLD(17);
        self.titleFontNormal = FONT(14);
        self.menuViewStyle = WMMenuViewStyleLine;
        self.progressColor = UIColor.whiteColor;
        self.progressWidth = PX(30);
        self.progressHeight = PX(5.0);
        self.menuItemWidth = 60;
        self.menuViewLayoutMode = WMMenuViewLayoutModeScatter;
        self.preloadPolicy = WMPageControllerPreloadPolicyNeighbour;
        self.showOnNavigationBar = YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)initPageInfo{
    NSMutableArray* pages = [NSMutableArray array];
    [pages addObject:@{@"index":@(0),@"title":@"收入",@"controller":@"XInComeViewController"}];
    [pages addObject:@{@"index":@(1),@"title":@"支出",@"controller":@"XExpendViewController"}];
    _pageInfos = pages;
}

#pragma mark -- WMPageControllerDataSource

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return _pageInfos.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    
    NSDictionary* pageInfo = _pageInfos[index];
    return pageInfo[@"title"];
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    
    NSDictionary *pageInfo = _pageInfos[index];
    NSString *controllerName = pageInfo[@"controller"];

    UIViewController* subontroller = [NSClassFromString(controllerName) new];
    return subontroller;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, 0, 120, 44);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    CGFloat y = 0;
    return CGRectMake(0, y, self.view.frame.size.width, SCREEN_HEIGHT - IPHONE_NAVIGATION_BAR_HEIGHT - IPHONE_TAB_BAR_HEIGHT);
}

@end
